<thead>
<tr>
    <td style="width: 250px">商品名称</td>
    <td style="width:150px;">商品规格</td>
    <td style="width:150px;">商品价格</td>
    <td style="width:150px;">参与兑换量:</td>
    <td>是否选择</td>
</tr>
</thead>
<tbody class="ui-sortable">

{loop $res $key $value}
<tr>
    <td>
        <img src="{$value['thumb']}"
             style="width:30px;height:30px;padding1px;border:1px solid #ccc">
        {$value['title']}
    </td>
    <td>{if $value['hasoption']==0}无规格{/if}{if $value['hasoption']==1}有规格{/if}</td>
    <td>¥{$value['marketprice']}</td>
    <td>
        <a href="javascript:;" data-toggle="ajaxEdit"
           data-href="{php echo webUrl('exchange/goods/stock',array('goodsid'=>$value['id']));}"
           style="display: inline;">{$value['exchange_stock']}</a>
    </td>
    <td>
        <div class="onoffswitch">
            <input type="checkbox" name="no_checkbox[]" class="onoffswitch-checkbox"
                   id="no{$value['id']}" value="{$value['id']}" {if $goods['goods']!=null && in_array($value['id'],$goods['goods'])}checked{/if}>
            <label class="onoffswitch-label" for="no{$value['id']}">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch"></span>
            </label>
        </div>
    </td>
</tr>
{/loop}

{php $i = 0;}
{loop $option2 $p}
{loop $option2[$i] $key $value}
{php $j = sizeof($option2[$i])-1;}
<tr>
    <td>
        <img src="{$option2[$i][0]['pic']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc">{$option2[$i][0]['gt']}
    </td>
    <td> {$value['title']}</td>
    <td>¥{$value['marketprice']}</td>
    <td>
        <a href="javascript:;" data-toggle="ajaxEdit"
           data-href="{php echo webUrl('exchange/goods/stock',array('optionid'=>$value['id']));}"
           style="display: inline;">{$value['exchange_stock']}</a>
    </td>
    <td>
        <div class="onoffswitch">
            <input type="checkbox" name="has_checkbox[]" class="onoffswitch-checkbox"
                   id="has{$value['id']}" value="{$value['goodsid']}_{$value['id']}" {if $goods['option'][$value['goodsid']]!=null && in_array($value['id'],$goods['option'][$value['goodsid']])}checked{/if}>
            <label class="onoffswitch-label" for="has{$value['id']}">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch"></span>
            </label>
        </div>
    </td>
</tr>
{php if($key>=$j)$i++;}
{/loop}
{/loop}


{loop $all $key $value}
<tr>
    <td>
        <img src="{$value['thumb']}"
             style="width:30px;height:30px;padding1px;border:1px solid #ccc">
        {$value['title']}
    </td>
    <td>{if $value['hasoption']==0}无规格{/if}{if $value['hasoption']==1}有规格{/if}</td>
    <td>¥{$value['marketprice']}</td>
    <td>
        <a href="javascript:;" data-toggle="ajaxEdit"
           data-href="{php echo webUrl('exchange/goods/stock',array('goodsid'=>$value['id']));}"
           style="display: inline;">{$value['exchange_stock']}</a>
    </td>
    <td>
        <div class="onoffswitch">
            <input type="checkbox" name="no_checkbox[]" class="onoffswitch-checkbox"
                   id="no{$value['id']}" value="{$value['id']}" {if $goods['goods']!=null &&  in_array($value['id'],$goods['goods'])}checked{/if}>
            <label class="onoffswitch-label" for="no{$value['id']}">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch"></span>
            </label>
        </div>
    </td>
</tr>
{/loop}
{php $i = 0;}
{loop $option $p}
{loop $option[$i] $key $value}
{php $j = sizeof($option[$i])-1;}
<tr>
    <td>
        <img src="{$option[$i][0]['pic']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc">{$option[$i][0]['gt']}
    </td>
    <td> {$value['title']}</td>
    <td>¥{$value['marketprice']}</td>
    <td>
        <a href="javascript:;" data-toggle="ajaxEdit"
           data-href="{php echo webUrl('exchange/goods/stock',array('optionid'=>$value['id']));}"
           style="display: inline;">{$value['exchange_stock']}</a>
    </td>
    <td>
        <div class="onoffswitch">
            <input type="checkbox" name="has_checkbox[]" class="onoffswitch-checkbox"
                   id="has{$value['id']}" value="{$value['goodsid']}_{$value['id']}" {if $goods['option'][$value['goodsid']]!=null &&  in_array($value['id'],$goods['option'][$value['goodsid']])}checked{/if}>
            <label class="onoffswitch-label" for="has{$value['id']}">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch"></span>
            </label>
        </div>
    </td>
</tr>
{php if($key>=$j)$i++;}
{/loop}
{/loop}
</tbody>